import { createRouter, createWebHistory } from 'vue-router'

// 患者端路由
const patientRoutes = [
  {
    path: '/patient',
    component: () => import('@/views/patient/Layout.vue'),
    redirect: '/patient/home',
    children: [
      {
        path: 'home',
        name: 'PatientHome',
        component: () => import('@/views/patient/home/index.vue'),
        meta: { title: '首页', icon: 'home' }
      },
      {
        path: 'order',
        name: 'PatientOrder',
        component: () => import('@/views/patient/order/index.vue'),
        meta: { title: '订单', icon: 'order' }
      },
      {
        path: 'consultation',
        name: 'PatientConsultation',
        component: () => import('@/views/patient/consultation/index.vue'),
        meta: { title: '在线咨询', icon: 'message' }
      },
      {
        path: 'profile',
        name: 'PatientProfile',
        component: () => import('@/views/patient/profile/index.vue'),
        meta: { title: '个人信息', icon: 'user' }
      }
    ]
  }
]

// 管理端路由
const adminRoutes = [
  {
    path: '/admin',
    component: () => import('@/views/admin/Layout.vue'),
    redirect: '/admin/statistics',
    children: [
      {
        path: 'statistics',
        name: 'AdminStatistics',
        component: () => import('@/views/admin/statistics/index.vue'),
        meta: { title: '需求统计', icon: 'statistics' }
      },
      {
        path: 'patient-management',
        name: 'AdminPatientManagement',
        component: () => import('@/views/admin/patient-management/index.vue'),
        meta: { title: '患者信息管理', icon: 'patient' }
      },
      {
        path: 'caregiver-management',
        name: 'AdminCaregiverManagement',
        component: () => import('@/views/admin/caregiver-management/index.vue'),
        meta: { title: '护工信息管理', icon: 'caregiver' }
      }
    ]
  }
]

// 护工端路由
const caregiverRoutes = [
  {
    path: '/caregiver',
    component: () => import('@/views/caregiver/Layout.vue'),
    redirect: '/caregiver/apply',
    children: [
      {
        path: 'apply',
        name: 'CaregiverApply',
        component: () => import('@/views/caregiver/apply/index.vue'),
        meta: { title: '陪护申请', icon: 'apply' }
      },
      {
        path: 'patient-info',
        name: 'CaregiverPatientInfo',
        component: () => import('@/views/caregiver/patient-info/index.vue'),
        meta: { title: '查看患者信息', icon: 'patient' }
      },
      {
        path: 'online-answer',
        name: 'CaregiverOnlineAnswer',
        component: () => import('@/views/caregiver/online-answer/index.vue'),
        meta: { title: '在线回答', icon: 'message' }
      },
      {
        path: 'profile',
        name: 'CaregiverProfile',
        component: () => import('@/views/caregiver/profile/index.vue'),
        meta: { title: '个人信息', icon: 'user' }
      }
    ]
  }
]

// 登录路由
const loginRoute = {
  path: '/login',
  name: 'Login',
  component: () => import('@/views/login/index.vue'),
  meta: { title: '登录' }
}

// 首页路由
const homeRoute = {
  path: '/',
  redirect: '/login'
}

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [homeRoute, loginRoute, ...patientRoutes, ...adminRoutes, ...caregiverRoutes]
})

export default router
